﻿using CocoaAni.Net.WebSockets.Server.ArgAdapters.Base;
using CocoaAni.Net.WebSockets.Server.Attributes;
using CocoaAni.Net.WebSockets.Server.DefineInfos;
using CocoaAni.Net.WebSockets.Server.Exceptions;

namespace CocoaAni.Net.WebSockets.Server.ArgAdapters;

public class MessageTextArgAdapter : MessageArgAdapter<string, TextArgAttribute>
{
    public override string? GetTargetParameter(MessageArgContext argContext)
    {
        if (!argContext.Message.IsText)
        {
            throw new WebSocketMessageArgException
                ($"Arg:{argContext.ArgDefineInfo.Name}, Must Use Text Message!",argContext.WebSocketContext);
        }
        return argContext.Message.ToString();
    }
}